<template>
    <h2>房号列表</h2>
    门店<select v-model="prose.storid">
                    <option value="">请选择</option>
                    <option :value="its.sid" v-for="its in stor">{{its.sname}}</option>
        </select>
    房型<select v-model="prose.rid">
                    <option value="">请选择</option>
                    <option :value="is.id" v-for="is in type">{{ is.rname }}</option>
         </select>
    <input type="button" value="查询" @click="showlist">
    <table>
        <tr>
            <td>房号</td>
            <td>房型</td>
            <td>门店</td>
            <td>房型图片</td>
            <td>状态</td>
            <td>操作</td>
        </tr>
        <tr v-for="item in list">
            <td>{{item.nname}}</td>
            <td>{{item.rname}}</td>
            <td>{{item.sname}}</td>
            <td><img :src="'https://localhost:7246'+item.rpicture" width="60" height="60"></td>
            <td>{{item.nstates==1?"上架":"下架"}}</td>
            <td><input v-if="item.nstates==1" type="button" value="下架" @click="shajnwo(item.nid,item.nstates)"><input v-if="item.nstates==0" type="button" value="上架" @click="shajnwo(item.nid,item.nstates)"><input type="button" value="移除" @click="delcow(item.nid)"></td>
        </tr>
    </table>
  </template>
  
  <script setup lang="ts">
  import {reactive, toRefs,onMounted} from 'vue'
  import {useRouter,useRoute} from 'vue-router'
  import axios from 'axios'
  const router=useRouter()
  const route=useRoute()

  let data:any=reactive({
    type:[],
    stor:[],
    list:[],
    prose:{
        storid:'',
        rid:''
    }
  })
  let {type,stor,list,prose} =toRefs(data)

  onMounted(()=>{
    gettype()
    getstore()
    showlist()
  })

  const gettype=()=>{
    axios({
        url:'/api/Price/Bindtype',
        method:'get'
    })
    .then(res=>{
        type.value=res.data.data;
    })
  }

  const getstore=()=>{
    axios({
        url:'/api/Num/Bindstore',
        method:'get'
    })
    .then(res=>{
        stor.value=res.data.data;
    }
    )
  }

  const showlist=()=>{
    let obj={
        storid:prose.value.storid,
        rid:prose.value.rid
    }
    axios({
        url:'/api/Num/GetAlls',
        method:'get',
        params:obj
    })
    .then(res=>{
        list.value=res.data.data;
    })
  }

  const shajnwo=(nid:any,nstates:any)=>{
    if(confirm("确认修改状态吗")){
        if(nstates==1){
            nstates=0;
        }else{
            nstates=1;
        }
        let obj={
            nid:nid,
            state:nstates
        }
        axios({
            url:'/api/Num/Updnsta',
            method:'get',
            params:obj
        })
        .then(res=>{
            if(res.data.data==1){
                alert("修改状态成功")
                showlist()
            }else{
                alert("修改状态失败")
            }
        })
    }
  }

  const delcow=(nid:any)=>{
    if(confirm("确定移除吗?")){
        let obj={
            nid:nid
        }
        axios({
            url:'/api/Num/Delete',
            method:'get',
            params:obj
        })
        .then(res=>{
            if(res.data.data==1){
                alert("移除房号信息成功")
                showlist()
            }else{
                alert("移除房号信息失败")
            }
        })
    }
  }
  </script>
  
  <style scoped>
  
  </style>